package com.pactera.miyuangroup.vo.response;

import java.io.Serializable;

/**
 * 返回结果
 *
 * @author Wangwu
 * @create 2018-03-30 下午4:14
 **/
public class ResultModel<T> implements Serializable {

    public static final long serialVersionUID = 1L;

    public ResultModel() {

    }

    public ResultModel(ResultStatusCode res) {
        this.code = res.getCode();
        this.msg = res.getCmsg();
    }

    public static ResultModel ok() {
        ResultModel r = new ResultModel(ResultStatusCode.OK);
        return r;
    }

    public static <T> ResultModel<T> ok(T t) {
        ResultModel r = new ResultModel<T>(ResultStatusCode.OK);
        r.setData(t);
        return r;
    }

    public static ResultModel fail() {
        ResultModel r = new ResultModel(ResultStatusCode.BUSINESS_ERROR);
        return r;
    }

    public static ResultModel fail(ResultStatusCode res) {
        ResultModel r = new ResultModel(res);
        return r;
    }

    public static ResultModel fail(String res) {
        ResultModel r = new ResultModel(ResultStatusCode.BUSINESS_ERROR);
        r.setMsg(res);
        return r;
    }

    public static ResultModel warning(ResultStatusCode res) {
        ResultModel r = new ResultModel(res);
        return r;
    }

    /**
     * 代码
     */
    private int code;


    /**
     * 消息
     */
    private String msg;

    /**
     * 数据
     */
    private T data;


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
